<template>
  <div>
    <div class="tl-form-line-title sub-title">
      <div class="simple-pager">
        <i class="el-icon-caret-left" :class="pageInfo.currentPage > 1 ? 'on' : ''" @click="prePage"></i>
        <i class="el-icon-caret-right" :class="pageInfo.currentPage < totalPage ? 'on' : ''" @click="nextPage"></i>
        当前：{{ pageInfo.currentPage }}/{{ totalPage }}，共{{ pageInfo.totalCount }}条
      </div>
      <div class="toolbar">
        <el-button type="text" size="medium" icon="el-icon-document-add" @click="openAddDialog('editForm')" v-if="!disableEditSubmit">新增</el-button>
      </div>
    </div>
    <!--表格渲染-->
    <el-table class="tl-table" ref="mainTable" size="small" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit>
      <el-table-column prop="name" label="会议主题" min-width="180px" sortable="custom" sort-by="name" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="dispmeettypeid" label="会议类型" width="200px" sortable="custom" sort-by="meettypeid" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="place" label="会议地点" width="200px" sortable="custom" sort-by="place" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="begintime" label="会议开始时间" width="170px" sortable="custom" sort-by="begintime" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="endtime" label="会议结束时间" width="170px" sortable="custom" sort-by="endtime" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="keywords" label="会议标签" width="180px" sortable="custom" sort-by="keywords" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="dispstate" label="会议状态" width="100px" sortable="custom" sort-by="state" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="launchusername" label="会议发起人" width="100px" sortable="custom" sort-by="launchusercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="操作" width="100px" v-slot="scope" fixed="right">
        <el-dropdown trigger="hover">
          <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
          <el-dropdown-menu>
            <el-dropdown-item icon="el-icon-edit" :disabled="disableEditSubmit" @click.native="openEditDialog('editForm', scope.row.id)">编辑</el-dropdown-item>
            <el-dropdown-item icon="el-icon-delete" :disabled="scope.row.state === 1" @click.native="doDelete(scope.row.id)">删除</el-dropdown-item>
            <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看 </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-table-column>
    </el-table>
    <meet-edit-comp ref="editComp" v-if="meetid || meetid === 0" @refresh="refreshComp" :sourcetype="sourcetype" :sourceid="projectid" :sourceapp="'mpm'" :meetId="Number(meetid)" :disableEditSubmit="disableEditSubmit || !canEdit" :attendcodes="attendcodes" :attendnames="attendnames"></meet-edit-comp>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import meetEditComp from "./meetEditComp"
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'mpmComp',
  mixins: [mixin_list],
  components: { meetEditComp },
  data() {
    return {
      url: {
        list: process.env.MEET_API + '/meet/meetManage/list',
        delete: process.env.MEET_API + '/meet/meetManage/delete',
        queryUploadedRecordOfMicro: process.env.MEET_API + '/meet/meetManage/queryUploadedRecordOfMicro'
      },
      pageInfo: {
        currentPage: 1, // 当前页面
        pageSize: 3, // 每页记录数
        pageSizes: ['10', '50', '100'],
        totalCount: 0 // 总数
      },
      meetid: 0,
      canEdit: true,
      uploaded: false
    }
  },
  computed: {
    totalPage() {
      let total = parseInt(this.pageInfo.totalCount / this.pageInfo.pageSize) + (this.pageInfo.totalCount % this.pageInfo.pageSize > 0 ? 1 : 0)
      if (total <= 0) {
        total = 1
      }
      return total
    }
  },
  props: {
    disableEditSubmit: {
      type: Boolean,
      default: true,
      required: true
    },
    sourcetype: {
      type: String,
      default: 'meetResolution',
      required: true
    },
    projectid: {
      type: [String, Number],
      default: '',
      required: true
    },
    attendcodes: {
      type: String,
      default: ''
    },
    attendnames: {
      type: String,
      default: ''
    }
  },
  methods: {
    nextPage() {
      if (this.pageInfo.currentPage < this.totalPage) {
        this.doChangeIndex(this.pageInfo.currentPage + 1)
      }
    },
    prePage() {
      if (this.pageInfo.currentPage > 1) {
        this.doChangeIndex(this.pageInfo.currentPage - 1)
      }
    },
    beforeLoadData() {
      this.$set(this.queryParam, 'qry_sourcetype', this.sourcetype)
      this.$set(this.queryParam, 'qry_sourceid', this.projectid)
      this.$set(this.queryParam, 'qry_sourceapp', 'mpm')
      return true
    },
    /** 打开编辑对话框 */
    openEditDialog(editForm, id) {
      if (!this.beforeOpenEditDialog(editForm, id)) {
        return
      }
      this.$refs.editComp.openMeetEdit()
      this.meetid = id
      this.canEdit = true
    },
    /** 打开详情对话框实现*/
    openViewDialog(editForm, id) {
      if (!this.beforeOpenViewDialog(editForm, id)) {
        return
      }
      this.$refs.editComp.openMeetEdit()
      this.meetid = id
      this.canEdit = false
    },
    /** 打开新增对话框实现 */
    openAddDialog(editForm, rowData) {
      if (!this.beforeOpenAddDialog(editForm, rowData)) {
        return
      }
      this.$refs.editComp.openMeetEdit()
      this.meetid = 0
      this.canEdit = true
    },
    /** 子组件通知父组件刷新 **/
    refreshComp() {
      this.doRefresh()
      this.getIsUploadedMeetRecordState()
    },
    /** 获取是否上传会议纪要的状态 **/
    getIsUploadedMeetRecordState() {
      let param = {
        sourcetype: this.sourcetype,
        sourceid: this.projectid,
        sourceapp: 'mpm'
      }
      getAction(this.url.queryUploadedRecordOfMicro, param).then((res) => {
        if (res.success) {
          this.uploaded = res.result.uploaded
        } else {
          this.$tap.alert('查询会议状态失败，请联系管理员')
        }
      })
    }
  },
  mounted() {
    this.getIsUploadedMeetRecordState()
  }
}
</script>

<style scoped></style>
